package com.chen.product.controller;

import cn.hutool.log.Log;
import com.chen.model.dto.h5.ProductSkuDto;
import com.chen.model.entity.product.Product;
import com.chen.model.entity.product.ProductSku;
import com.chen.model.vo.common.Result;
import com.chen.model.vo.common.ResultCodeEnum;
import com.chen.model.vo.h5.ProductItemVo;
import com.chen.product.service.ProductService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author cgj
 * @date 4/14/25 7:47 PM
 */

/**
 *
 http://localhost:8500/api/product/1/10?category1Id=&category2Id=&category3Id=&keyword=&brandId=&order=1&pageNo=1&pageSize=10&pages=1
 */
@RequestMapping("/api/product")
@RestController
public class ProductController {
    @Autowired
    private ProductService productService;

    /**
     * /api/product/getProductSkuBySkuId/{skuId}
     * 根据skuId,查询sku
     */
    @GetMapping("/getProductSkuBySkuId/{skuId}")
    public ProductSku getProductSkuBySkuId(@PathVariable Long skuId){
        ProductSku productSku= productService.getProductSkuBySkuId(skuId);
        return productSku;
    }
    /**
     * 分页条件查询商品SKU
     * @param pageNum
     * @param pageSize
     * @param productSkuDto
     * @return
     */
    @GetMapping("/{pageNum}/{pageSize}")
    public Result<PageInfo>  selectByPageAndCondition(@PathVariable Integer pageNum,
                                                      @PathVariable Integer pageSize,
                                                      ProductSkuDto productSkuDto){
        PageInfo<ProductSku> pageInfo=productService.selectByPageAndCondition(pageNum,pageSize,productSkuDto);
        return Result.build(pageInfo, ResultCodeEnum.SUCCESS);
    }


    /**
     *
     * 根据skuID查询商品的详情
     * @param skuId
     * @return
     */
    @GetMapping("/item/{skuId}")
    public Result<ProductItemVo> getItem(@PathVariable Long skuId){
          ProductItemVo productItemVo=productService.getItem(skuId);
        return Result.build(productItemVo,ResultCodeEnum.SUCCESS);
    }
}
